<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <jsp:include page="../../../../../head.jsp"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>角色可管理权限设置</title>
    <style type="text/css">
        .buttons li {
            list-style-type: none;
        }

        .buttons li {
            font-size: 65%;
        }
    </style>
</head>
<script type="text/javascript">
    var dataUrl = "role-mmoduledata";
    var roleId = "${id}";
    var zTree;
    var setting = {
        async: {
            enable: true,
            url: dataUrl,
            autoParam: ["id=mid"],
            otherParam: ["rid", roleId],
            dataFilter: function (treeId, parentNode, childNodes) {
                if (!childNodes)
                    return null;
                roleId = childNodes.id;
                return childNodes.modules;
            }
        },
        check: {
            enable: true
        },
        data: {
            simpleData: {
                pIdKey: "parent.id"
            }
        },
        callback: {
            onClick: function (event, treeId, treeNode, clickFlag) {
                jw.dialog({
                              iframe: "role-mpermissions?rid=" + roleId
                                      + "&mid=" + treeNode.id,
                              width: 500,
                              height: 230
                          });
            },
            onNodeCreated: function (event, treeId, treeNode) {
                zTree.reAsyncChildNodes(treeNode, "refresh");
            }
        }
    };

    function refresh() {
        zTree.reAsyncChildNodes(null, "refresh");
    }

    function save() {
        if (roleId) {
            var changeNodes = zTree.getChangeCheckedNodes();
            var checkedNodes = zTree.getCheckedNodes();
            if (changeNodes != null && changeNodes.length != 0) {
                submitTree(checkedNodes, "role-saveRoleMModule", {
                    "manageModules{n}.id": "id",
                    "manageModules{n}.checked": "checked"
                }, {
                               "id": roleId
                           }, "n", function (data, textStatus, jqXHR) {
                    jw.alert(data.msg, {
                        onOk: function () {
                            if (data.result) {
                                tree_refresh(zTree);
                            }
                        }
                    });
                });
            }
        }
    }

    $(document).ready(function () {
        $.fn.zTree.init($("#moduletree"), setting);
        zTree = $.fn.zTree.getZTreeObj("moduletree");
        $("input:button").button();
    });
</script>
<body>
<div>
    <ul id="moduletree" class="ztree"></ul>
    <ul class="buttons">
        <li><input id="saveButton" type="button" onclick="save()"
                   value="保存"/><input type="button" value="重置" onclick="refresh()"/></li>
    </ul>
</div>
</body>
</html>
